import time

import flask
import json
from flask import request, g

# 创建机械臂对象
server = flask.Flask(__name__)


@server.route('/api/reset_arm', methods=['GET'])
def reset_arm():
    # for i in range(6):
    #     Arm.Arm_serial_servo_write(i + 1, 90, 1000)
    #     time.sleep(.01)
    return 'ok'


@server.route('/api/start_study', methods=['GET'])
def start_study():
    return 'ok'


@server.route('/api/finish_study', methods=['GET'])
def finish_study():
    return 'ok'


@server.route('/api/get_position', methods=['GET'])
def get_position():
    pos = []
    for i in range(6):
        print(aa)
        pos.append(aa)
        time.sleep(.01)
    return json.dumps(pos, ensure_ascii=False)


@server.route('/api/move', methods=['GET'])
def move():
    data = eval(request.get_data(as_text=True))
    print(data)
    position = data['position'].decode('utf-8').split(',')
    print(position)
    # Arm.Arm_serial_servo_write6(position[0], position[1], position[2], position[3], position[4], position[5], 400)
    for i in range(6):
        print(position[i])
        time.sleep(.01)
    return 'ok'


if __name__ == '__main__':
    server.run(debug=True, port=6666, host='0.0.0.0')
